package com.kuaimacode.kframework.agent.services.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuaimacode.kframework.agent.util.SessionUtil;
import com.kuaimacode.kframework.common.Constant;
import com.kuaimacode.kframework.mybatis.mapper.service.OneClassMapper;
import com.kuaimacode.kframework.mybatis.models.service.OneClass;
import org.apache.ibatis.annotations.One;
import org.springframework.data.redis.repository.query.ExampleQueryMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author anzy
 * @date 2019/04/13
 */
@Service
public class  OneClassService extends ServiceImpl<OneClassMapper, OneClass> {

    	/**
    	 *  分页查找所有的数据
    	 * @param pageNum 当前页码，从1开始
    	 * @param pageSize  一页显示多少行
    	 * @return
    	 */
    	public PageInfo<OneClass> findAll(int pageNum, int pageSize) {
    		PageHelper.startPage(pageNum, pageSize);
			QueryWrapper wrapper = new QueryWrapper();
    		List<OneClass> datas = baseMapper.queryAgentOneClass(SessionUtil.getAgentId());
    		return new PageInfo<OneClass>(datas);
    	}

    	//根据大类编号判断是否存在
    	public OneClass queryOneClassByServiceCode(String serviceCode){
    		QueryWrapper queryWrapper = new QueryWrapper();
    		queryWrapper.eq("service_class",serviceCode);
    		queryWrapper.eq("agent_id",SessionUtil.getAgentId());
    		return baseMapper.selectOne(queryWrapper);
		}

	/**
	 * 查询分站开通的一级分类
	 * @return
	 */
		public List<OneClass> queryOneClass(){
			QueryWrapper queryWrapper = new QueryWrapper();
			queryWrapper.eq("status", Constant.DeleteStateEnum.NORMAL.getCode());
			queryWrapper.eq("agent_id",SessionUtil.getAgentId());
    		return baseMapper.selectList(queryWrapper);
		}

	/**
	 * 查询分站已经添加的一级分类
	 * @return
	 */
	public List<OneClass> queryOneClassAll(){
		QueryWrapper queryWrapper = new QueryWrapper();
		queryWrapper.eq("agent_id",SessionUtil.getAgentId());
		return baseMapper.selectList(queryWrapper);
	}



}

